package net.sourceforge.javaocr.gui;

import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.UIManager;

import net.sourceforge.javaocr.gui.neuralNetOCR.TrainingImageSpec;
import net.sourceforge.javaocr.ocrPlugins.neuralNetOCR.OCR;

public class GUIController
{

    private MainFrame mainFrame;

    public GUIController()
    {
        setLookandFeel();
        mainFrame = new MainFrame(this);
    }

    public void showGUI()
    {
        mainFrame.setVisible(true);
    }

    private void setLookandFeel()
    {
        try
        {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        }
        catch (Exception ex)
        {
            Logger.getLogger(GUIController.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void repaint()
    {
        mainFrame.repaint();
    }

    /**
     * Realizo el entrenamiento para poder realizar el ocr de targImageLoc
     * @param imgs Imagenes que sirven como entrenamiento de la red
     * @param targImageLoc Imagen a la que se aplicará el OCR
     * @return devuelvo el string
     */
    public String performNeuralNetOCR(ArrayList<TrainingImageSpec> imgs, String targImageLoc) throws Exception {
    	OCR ocrScannerNeural = new OCR();
    	ocrScannerNeural.init(imgs);
    	ocrScannerNeural.training();
    	return ocrScannerNeural.scan(targImageLoc);
    }

	
    @SuppressWarnings("unused")
	private static final Logger LOG = Logger.getLogger(GUIController.class.getName());
}
